define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'data/shopdaytrade/index' + location.search,
                    add_url: 'data/shopdaytrade/add',
                    edit_url: 'data/shopdaytrade/edit',
                    del_url: 'data/shopdaytrade/del',
                    multi_url: 'data/shopdaytrade/multi',
                    import_url: 'data/shopdaytrade/import',
                    table: 'shop_day_trade',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'shop_id', title: __('店铺ID')},
                        {field: 'shop_name', title: __('店铺名字'), operate: 'LIKE'},
                        {field: 'create_time', title: __('时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'total_amount', title: __('总金额'), operate:false,sortable:true},
                        {field: 'book_amount', title: __('棋牌金额'), operate:false,sortable:true},
                        {field: 'tq_amount', title: __('台球金额'), operate:false,sortable:true},
                        {field: 'book_pay_amount', title: __('棋牌支付'), operate:false,sortable:true},
                        {field: 'charge_amount', title: __('充值金额'), operate:false,sortable:true},
                        {field: 'tuan_amount', title: __('团购券购买'), operate:false,sortable:true},
                        {field: 'dou_amount', title: __('抖音核销'), operate:false,sortable:true},
                        {field: 'mt_amount', title: __('美团核销'), operate:false,sortable:true},
                        {field: 'balance_amount', title: __('余额抵扣'), operate:false,sortable:true},
                        {field: 'tuan_amount', title: __('团购券抵扣'), operate:false,sortable:true},
                        {field: 'profit', title: __('抽点'), operate:false,sortable:true},
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [],
                            formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                $(table).data("operate-edit", null);
                                $(table).data("operate-del", null);

                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            }
                        }]
                ]
            });


            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
